﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CubicFWNet.Data.Models;
using CubicFWNet.Data.SystemManager;
using CubicFWNet.Data.ViewModal;


namespace CubicFWNet.Application.SystemManager
{
    public class InventoryApp
    {

        private readonly InventoryRepository _inventoryRepository = new InventoryRepository();

        /// <summary>
        /// 获取库存列表
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public IEnumerable<InventoryView> GetInventoryList(int categoryid, int storageId, string name)
        {
            return _inventoryRepository.GetInventoryList(categoryid, storageId, name);
        }

        public int Add(Inventory inv)
        {
            return _inventoryRepository.Insert(inv);
        }

        public int Update(Inventory inv)
        {
            return _inventoryRepository.Update(inv);
        }

        /// <summary>
        /// 根据产品id获取库存
        /// </summary>
        /// <param name="pid"></param>
        /// <returns></returns>
        public Inventory GetInfoByPID(Guid? pid,int storageid)
        {
            return _inventoryRepository.IQueryable(a => a.ProuctId == pid && a.StorageId == storageid).FirstOrDefault();
        }

        public Inventory GetInfo(Guid id)
        {
            return _inventoryRepository.FindEntity(i => i.Id == id);
        }

        public void Delete(Guid id)
        {
            _inventoryRepository.Delete(u => u.Id == id);
        }
    }
}
